/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ruipengkj.bean.ViewPurchaseOrderSummary;
import com.ruipengkj.commons.base.query.BaseQuery;
import com.ruipengkj.commons.base.query.PageModel;
import com.ruipengkj.dao.ViewPurchaseOrderSummaryDao;
import com.ruipengkj.service.ViewPurchaseOrderSummaryService;
/**
 * 说明：
 * 商品采购汇总表Service层接口实现
 * @Author：李智深
 * @Date：2012-03-16
 */
@Service
public class ViewPurchaseOrderSummaryServiceImpl implements ViewPurchaseOrderSummaryService{

	@Resource
	private ViewPurchaseOrderSummaryDao ViewPurchaseOrderSummaryDao;//DAO层
	
	//根据条件查询
	@Override
	public List<ViewPurchaseOrderSummary> findService(ViewPurchaseOrderSummary entity) throws Exception {
		String hql = "select o from ViewPurchaseOrderSummary o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return ViewPurchaseOrderSummaryDao.findDao(hql, whereHQL.toString(), param, orderby);
	}

	//根据ID翻页查询
	@Override
	public PageModel<ViewPurchaseOrderSummary> getScrollService(int firstResult,
			int maxResult, ViewPurchaseOrderSummary entity) throws Exception {
		String hql = "select o from ViewPurchaseOrderSummary o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(entity.getName()!=null&&!entity.getName().equals("")){
				whereHQL.append("o.name").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
				param.add("%"+entity.getName()+"%");
			}
			if(entity.getEmpName()!=null && !entity.getEmpName().equals("")){
				whereHQL.append("o.empName").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
				param.add("%"+entity.getEmpName()+"%");
			}
			if(null!=entity.getAddTime()&&!("").equals(entity.getAddTime())){
				whereHQL.append("addTime>=?").append(BaseQuery.AND);
				param.add(entity.getAddTime());
			}
			if(null!=entity.getEndTime()&&!("").equals(entity.getEndTime())){
				whereHQL.append("addTime<=?").append(BaseQuery.AND);
				param.add(entity.getEndTime());
			}
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return ViewPurchaseOrderSummaryDao.getScrollDao(hql, whereHQL.toString(), param, firstResult, maxResult, orderby);
	}

	//修改
	@Override
	public void modifyService(ViewPurchaseOrderSummary entity) throws Exception {
		ViewPurchaseOrderSummaryDao.modifyDao(entity);
		
	}
	//添加
	@Override
	public void saveService(ViewPurchaseOrderSummary entity) throws Exception {
		ViewPurchaseOrderSummaryDao.saveDao(entity);
	}

	//根据ID删除
	@Override
	public void deleteService(String id) throws Exception {
		ViewPurchaseOrderSummaryDao.deleteDao(id);
		
	}
	//根据ID查询
	@Override
	public ViewPurchaseOrderSummary getByIdService(String id) throws Exception {
		return ViewPurchaseOrderSummaryDao.getByIdDao(id);
	}
	//添加或修改
	@Override
	public void saveOrUpdateService(ViewPurchaseOrderSummary entity) throws Exception {
		ViewPurchaseOrderSummaryDao.saveOrUpdateDao(entity);
	}
	//添加返回ID
	@Override
	public Serializable saveRetService(ViewPurchaseOrderSummary entity) throws Exception {
		return ViewPurchaseOrderSummaryDao.saveRetDao(entity);
	}

	public ViewPurchaseOrderSummaryDao getViewPurchaseOrderSummaryDao() {
		return ViewPurchaseOrderSummaryDao;
	}

	public void setViewPurchaseOrderSummaryDao(
			ViewPurchaseOrderSummaryDao viewPurchaseOrderSummaryDao) {
		ViewPurchaseOrderSummaryDao = viewPurchaseOrderSummaryDao;
	}

	@Override
	public List<ViewPurchaseOrderSummary> findExportService(
			ViewPurchaseOrderSummary entity) throws Exception {
		String hql = "select o from ViewPurchaseOrderSummary o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(entity.getName()!=null&&!entity.getName().equals("")){
				whereHQL.append("o.name").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
				param.add("%"+entity.getName()+"%");
			}
			if(null!=entity.getAddTime()&&!("").equals(entity.getAddTime())){
				whereHQL.append("addTime>=?").append(BaseQuery.AND);
				param.add(entity.getAddTime());
			}
			if(null!=entity.getEndTime()&&!("").equals(entity.getEndTime())){
				whereHQL.append("addTime<=?").append(BaseQuery.AND);
				param.add(entity.getEndTime());
			}
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return ViewPurchaseOrderSummaryDao.findDao(hql, whereHQL.toString(), param, orderby);
	}
}
